package com.sec.android.app.myfiles.listener;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

import com.sec.android.app.myfiles.listener.ListenerMgr.LifeCycle;
import com.sec.android.app.myfiles.log.Log;

public class SidesyncListenerImp extends AbsBroadcastReceiverImp {
    public static final String SIDESYNC_ACTION_DRAG_DROP = "com.sec.android.sidesync.source.DROP_DRAG";
    public static final String SIDESYNC_ACTION_EDIT_MODE = "com.sec.android.sidesync.myfiles.request_edit";
    public static final String SIDESYNC_ACTION_SELECT_ALL = "com.sec.android.sidesync.myfiles.request_editall";
    public static final String SIDESYNC_ACTION_REQUEST_FILE = "com.sec.android.sidesync.myfiles.request_file";
    public static final String SIDESYNC_ACTION_REQUEST_URI = "com.sec.android.sidesync.myfiles.request_uri";

    public static final int SIDESYNC_CONNNECTED = 1;

    public interface SidesyncDragDrop {
        void onSidesyncDragDrop();
        void onSidesyncEditMode();
        void onSidesyncSelectAll();
        void onSidesyncSelectedItemPath();
        void onSidesyncCurrentPath();
    }

    private SidesyncDragDrop mProc;

    public static SidesyncListenerImp getInstance(Context context, SidesyncDragDrop proc, LifeCycle registerTime, LifeCycle unregisterTime) {
        return new SidesyncListenerImp(context, proc, registerTime, unregisterTime);
    }

    private SidesyncListenerImp(Context context, SidesyncDragDrop proc, LifeCycle registerTime, LifeCycle unregisterTime) {
        super(context, registerTime, unregisterTime);
        mProc = proc;
    }

    @Override
    IntentFilter getIntentFilter() {
        IntentFilter ret = new IntentFilter();
        ret.addAction(SIDESYNC_ACTION_DRAG_DROP);
        ret.addAction(SIDESYNC_ACTION_EDIT_MODE);
        ret.addAction(SIDESYNC_ACTION_SELECT_ALL);
        ret.addAction(SIDESYNC_ACTION_REQUEST_FILE);
        ret.addAction(SIDESYNC_ACTION_REQUEST_URI);

        return ret;
    }

    @Override
    BroadcastReceiver getBroadcastReceiver() {
        BroadcastReceiver ret = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
             if (mProc != null) {
                    if (SIDESYNC_ACTION_DRAG_DROP.equals(intent.getAction())) {
                        mProc.onSidesyncDragDrop();
                    }else if(SIDESYNC_ACTION_EDIT_MODE.equals(intent.getAction())) {
                        mProc.onSidesyncEditMode();
                    }else if(SIDESYNC_ACTION_SELECT_ALL.equals(intent.getAction())) {
                        mProc.onSidesyncSelectAll();
                    }else if(SIDESYNC_ACTION_REQUEST_FILE.equals(intent.getAction())) {
                        mProc.onSidesyncSelectedItemPath();
                        Log.d(this, "SIDESYNC_ACTION_REQUEST_FILE");
                    }else if(SIDESYNC_ACTION_REQUEST_URI.equals(intent.getAction())) {
                        mProc.onSidesyncCurrentPath();
                        Log.d(this, "SIDESYNC_ACTION_REQUEST_URI");
                    }
                }
            }
        };

        return ret;
    }

}
